<?php


class asynsHttp
{
    /**
     * 以get模拟网络请求
     *
     * @param array $urlPath HTTP请求URL地址
     * @param array $query GET请求参数
     * @param array $options CURL参数
     *
     * @return boolean|string
     */
    public static function get($urlPath, $query = [], $options = [])
    {
        $cli = new \Swoole\Coroutine\Http\Client($urlPath['url'], 443, true);
        $cli->setHeaders([
            'Host' => $urlPath['url'],
            "User-Agent" => 'Chrome/49.0.2587.3',
            'Accept' => 'text/html,application/xhtml+xml,application/xml',
            'Accept-Encoding' => 'gzip',
        ]);
        $cli->get($urlPath['path']);
        $res =$cli->body;
        $cli->close();
        return $res;
    }


    public static function download($url,$path,$dir){

        $cli = new \Swoole\Coroutine\Http\Client($url, 443, true);
        $cli->download('/'.$path,$dir);
    }
}
